package com.lufei.dh.bottom.MultAuto;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.lufei.dh.R;

import me.drakeet.multitype.ItemViewBinder;

/**
 * 版权：易金卡沃 版权所有
 * <p>
 * 作者：lufei
 * <p>
 * 创建日期：2018/7/2
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
public class Item_AutoViewBinder extends ItemViewBinder<Item_Auto, Item_AutoViewBinder.ViewHolder> {
    private Context context;
    private int lastShownAnimationPosition;
    public Item_AutoViewBinder(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_item__auto, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Item_Auto item_Auto) {
        holder.textView.setText(item_Auto.text);
//        setAnimation(holder.textView, holder.getAdapterPosition());
    }

    private void setAnimation(@NonNull View viewToAnimate, int position) {
        if (position > lastShownAnimationPosition) {
            Animation animation = AnimationUtils.loadAnimation(viewToAnimate.getContext(), android.R.anim.slide_in_left);
            viewToAnimate.startAnimation(animation);
            lastShownAnimationPosition = position;
        }
    }
    static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView textView;

        ViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.id_item_text);
        }
    }

}
